/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: 沈小白 2020-07-22 $
 */<template> 
	<view class="container" >
		<view class="type-navbar">
			<block v-for="(item,index) in navList" :key="index">
				<view class="type-box" >
					<view @tap="changeTab" class="type-navbar-item" :class="[typeActive==index?'type-item-on':'']" :data-idx="index" :data-status="item.id" >{{item.name}} </view>
					
				</view>
			</block>
			
			
		</view>
		
		<scroll-view @scrolltolower="onBottom" class="goods-container" scroll-y="true" scroll-with-animation="true" v-if="comment">		
			<block v-for="(item,index) in comment" :key="index" v-if="comment||comment.length>0">
				<view class="goods-box">
					<navigator class="goods-img" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id='+item.goods_id" role="navigation">
						<image class="wh100" :src="hostUrl+'/mall/goods/thumb_image?goods_id='+ item.goods_id+'&width='+goodsImgWidth+'&height='+goodsImgHeight+'&'+item.goods_id+'.'+imgType"role="img"></image>
					</navigator>
					<navigator class="goods-desc" :url="'/pages/goods/goodsInfo/goodsInfo?goods_id='+item.goods_id" role="navigation">
						<view class="goods-name ellipsis-1">{{item.goods_name}} </view>
						<view class="goods-name ellipsis-1">{{item.spec_key_name?item.spec_key_name:''}}</view>
						<view class="buy-time">购买时间：{{item.pay_time}}</view>
					</navigator>
					<navigator class="little-btn-2 comment-button " :hidden="item.is_comment==0" :data-idx="index" :url="'/pages/user/order_detail/order_detail?order_sn='+item.order.order_sn" role="navigation">
						<!-- <image class="button-icon" :src="imgUrl+'user/c23.png'" role="img"></image> -->
						查看订单
					</navigator>
					<view @tap="commentTap" class="little-btn-1 comment-button" :hidden="!item.is_comment==0" :data-idx="index">
						<!-- <image class="button-icon" :src="imgUrl+'user/co.png'"  role="img"></image> -->
						评价订单
					</view>
				</view>
			</block>
			<view class="no-data" v-if="!comment||comment.length==0">
				<image :src="imgUrl+'cart/cart-null.png'" class="cart-image"/>
				<view class="no-data-title">没有找到相关的记录</view>
				<navigator url="/pages/index/index" class="lookat" open-type="navigate"> 去逛逛 </navigator>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import common from "@/common/common.js";
	import {mapState} from "vuex";
	import config from "@/api/config.js";
	import {getComment} from "@/api/api.js";
	export default {
		data() {
			return {
				hostUrl:config.host,
				imgUrl:config.imgUrl,
				loginInfo:"",
				navList:[
					{name:"全部评价",id:""},
					{name:"待评价",id:"0"},
					{name:"已评价",id:"1"}
				],
				typeActive:0,//状态
				comment:[],//评价
				total:"",//条数
				params:{
					is_comment:"",//空 全部 0,待评价1已评价
					p:1,
				},
				option:"",
			};
		},
		computed: {
			...mapState(['hasLogin','imgType','goodsImgHeight','goodsImgWidth'])
		},
		onLoad(option){
			this.option=option
			if(this.hasLogin){
				console.log(this.option)
				this.navList.forEach((i,index)=>{
					if(this.option.status==i.id){
						console.log(i)
						this.params.is_comment=i.id
						this.typeActive=index
						
					}
				})
				this.getComment(this.params)
			}else{
				common.islogin()
			}
		},
		onShow(){
			
		},
		methods:{
			/*请求评价数据*/ 
			getComment(params){
				getComment(params).then(res=>{
					if(res){
						console.log(res)
						this.total=res.total;
						res.records.forEach((i,index)=>{
							var time=common.format(i.order.pay_time)
							i.pay_time=time
						})
						this.comment=this.comment.concat(res.records)
					}
					
				})
			},
			/*切换状态*/
			changeTab(e){
				console.log(e)
				let index= e.currentTarget.dataset.idx;
				let type= e.currentTarget.dataset.status;
				this.typeActive=index
				this.params.p=1;
				this.params.is_comment=type;
				this.comment.length=0;
				this.getComment(this.params)
			},
			onBottom(){//下拉加载数据
				
				if(this.comment.length==this.total){
					common.toast("none","加载完了",2000)
					 return false;
				}
				this.params.p++;
				if(this.loginInfo!=null){
					this.getComment(this.params)
				}
			},
			go(){
				console.log("滚动")
			},
			/*评价*/ 
			commentTap(e){
				console.log(e)
				let index=e.currentTarget.dataset.idx
				let comment=this.comment[index]
				console.log(comment)
				let params=common.Obj2Str({
					"goods_name":comment.goods_name,
					"goods_id":comment.goods_id,
					"order_id":comment.order_id,
					"spec_key_name":comment.spec_key_name,
					"rec_id":comment.rec_id,
					"order_sn":comment.order.order_sn
				})
				uni.navigateTo({
					url:'/pages/user/add_comment/add_comment?' + params 
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		display: flex;
		flex-direction: column;
		height: 100%;
		}
	.container{
		padding-bottom: 0;
		height: 100%;
	}
	.type-navbar {
		white-space: nowrap;
		display: flex;
		width: 100%;
		height: 80rpx;
		background-color: #fff;
	}

	.type-box {
		width: 33.3333333333%;
		box-sizing: border-box;
		font-size: 28rpx;
		line-height: 76rpx;
		padding: 0 20rpx;
		text-align: center;
		display: inline-block;
		overflow: hidden;
	}

	.type-navbar-item {
		border-bottom: 4rpx solid #fff;
	}

	.type-item-on {
		border-bottom: 4rpx solid #ff3b3b;
	}

	.goods-container {
		margin: 20rpx 0;
		background-color: #f5f5f5;
		flex: 1;
		overflow: auto;
	}

	.goods-box {
		background: #fff;
		position: relative;
		padding: 20rpx 30rpx 0;
		font-size: 28rpx;
		clear: both;
		width: 710rpx;
		margin: 0 auto;
		border-radius: 10rpx;
		overflow: hidden;
		box-sizing: border-box;
		margin-bottom: 20rpx;
	}

	.goods-img {
		float: left;
		height: 100rpx;
		width: 100rpx;
	}

	.goods-desc {
		float: left;
		width: 530rpx;
		margin-left: 20rpx;
	}

	.goods-name {
		height: 44rpx;
		line-height: 44rpx;
		overflow: hidden;
	}

	.buy-time {
		margin-top: 20rpx;
		font-size: 26rpx;
		color: #b3b3b3;
	}

	.comment-button {
		font-size: 26rpx;
		// color: #ff3b3b;
		float: right;
		padding: 0rpx 10rpx;
		// border: 1rpx #ff3b3b solid;
		margin-bottom: 20rpx;
		border-radius: 10rpx;
	}

	.change-order {
		color: #c2c2c2;
		border: 1rpx #c2c2c2 solid;
		border-radius: 10rpx;
	}

	.button-icon {
		height: 26rpx;
		width: 26rpx;
	}
</style>
